<?php
/**
 * SimpleRbacUserModel.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/26
 * Time: 22:34
 */
namespace app\common\auto_curd\php_system\model;

use think\Db;

class SimpleRbacUserModel
{
    /**
     * ID
     */
    protected $id = '';
    public function getId()
    {
        return $this->id;
    }
    public function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * 锁定(0:否,1:是)
     */
    protected $lock = '0';
    public function getLock()
    {
        return $this->lock;
    }
    public function setLock($lock)
    {
        $this->lock = $lock;
    }
    
    /**
     * 头像
     */
    protected $avatar = '0';
    public function getAvatar()
    {
        return $this->avatar;
    }
    public function setAvatar($avatar)
    {
        $this->avatar = $avatar;
    }
    
    /**
     * 性别(1:男,2:女)
     */
    protected $sex = '1';
    public function getSex()
    {
        return $this->sex;
    }
    public function setSex($sex)
    {
        $this->sex = $sex;
    }
    
    /**
     * 创建时间
     */
    protected $create_ts = '0';
    public function getCreateTs()
    {
        return $this->create_ts;
    }
    public function setCreateTs($create_ts)
    {
        $this->create_ts = $create_ts;
    }
    
    /**
     * 修改时间
     */
    protected $update_ts = '0';
    public function getUpdateTs()
    {
        return $this->update_ts;
    }
    public function setUpdateTs($update_ts)
    {
        $this->update_ts = $update_ts;
    }
    
    /**
     * 平台ID
     */
    protected $platform_id = '0';
    public function getPlatformId()
    {
        return $this->platform_id;
    }
    public function setPlatformId($platform_id)
    {
        $this->platform_id = $platform_id;
    }
    
    /**
     * 用户名
     */
    protected $username = '';
    public function getUsername()
    {
        return $this->username;
    }
    public function setUsername($username)
    {
        $this->username = $username;
    }
    
    /**
     * 电话
     */
    protected $phone = '';
    public function getPhone()
    {
        return $this->phone;
    }
    public function setPhone($phone)
    {
        $this->phone = $phone;
    }
    
    /**
     * 密码提示
     */
    protected $pawrd = '';
    public function getPawrd()
    {
        return $this->pawrd;
    }
    public function setPawrd($pawrd)
    {
        $this->pawrd = $pawrd;
    }
    
    /**
     * 加密密码
     */
    protected $password = '';
    public function getPassword()
    {
        return $this->password;
    }
    public function setPassword($password)
    {
        $this->password = $password;
    }
    
    /**
     * 昵称
     */
    protected $nick_name = '';
    public function getNickName()
    {
        return $this->nick_name;
    }
    public function setNickName($nick_name)
    {
        $this->nick_name = $nick_name;
    }
    
    /**
     * 真实姓名
     */
    protected $real_name = '';
    public function getRealName()
    {
        return $this->real_name;
    }
    public function setRealName($real_name)
    {
        $this->real_name = $real_name;
    }
    
    /**
     * 邮箱
     */
    protected $email = '';
    public function getEmail()
    {
        return $this->email;
    }
    public function setEmail($email)
    {
        $this->email = $email;
    }
    
    /**
     * 角色(,1,2,3,)
     */
    protected $roles = '';
    public function getRoles()
    {
        return $this->roles;
    }
    public function setRoles($roles)
    {
        $this->roles = $roles;
    }
    
    /**
     * 用户简介
     */
    protected $remark = '';
    public function getRemark()
    {
        return $this->remark;
    }
    public function setRemark($remark)
    {
        $this->remark = $remark;
    }
    
    /**
     * 权限节点(,1,2,3,)
     */
    protected $nodes = '';
    public function getNodes()
    {
        return $this->nodes;
    }
    public function setNodes($nodes)
    {
        $this->nodes = $nodes;
    }
    
    /**
     * constructor.
     * @param array $data
     */
    public function __construct($data=[])
    {

        // ID
        if(isset($data['id']))
        {
            $this->id = $data['id'];
        }

        // 锁定(0:否,1:是)
        if(isset($data['lock']))
        {
            $this->lock = $data['lock'];
        }

        // 头像
        if(isset($data['avatar']))
        {
            $this->avatar = $data['avatar'];
        }

        // 性别(1:男,2:女)
        if(isset($data['sex']))
        {
            $this->sex = $data['sex'];
        }

        // 创建时间
        if(isset($data['create_ts']))
        {
            $this->create_ts = $data['create_ts'];
        }

        // 修改时间
        if(isset($data['update_ts']))
        {
            $this->update_ts = $data['update_ts'];
        }

        // 平台ID
        if(isset($data['platform_id']))
        {
            $this->platform_id = $data['platform_id'];
        }

        // 用户名
        if(isset($data['username']))
        {
            $this->username = $data['username'];
        }

        // 电话
        if(isset($data['phone']))
        {
            $this->phone = $data['phone'];
        }

        // 密码提示
        if(isset($data['pawrd']))
        {
            $this->pawrd = $data['pawrd'];
        }

        // 加密密码
        if(isset($data['password']))
        {
            $this->password = $data['password'];
        }

        // 昵称
        if(isset($data['nick_name']))
        {
            $this->nick_name = $data['nick_name'];
        }

        // 真实姓名
        if(isset($data['real_name']))
        {
            $this->real_name = $data['real_name'];
        }

        // 邮箱
        if(isset($data['email']))
        {
            $this->email = $data['email'];
        }

        // 角色(,1,2,3,)
        if(isset($data['roles']))
        {
            $this->roles = $data['roles'];
        }

        // 用户简介
        if(isset($data['remark']))
        {
            $this->remark = $data['remark'];
        }

        // 权限节点(,1,2,3,)
        if(isset($data['nodes']))
        {
            $this->nodes = $data['nodes'];
        }

    }
    
    /**
     * 获取分页信息
     * @param $where
     * @param array $extend
     * @return \think\Paginator
     */
    static public function paginate($where,$extend=[])
    {
        $handler = Db::table('simple_rbac_user');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->paginate();
    }
    
    /**
     * 添加|修改
     * @param $flag
     * @param $data
     * @param array $extend
     * @return int|string
     */
    static public function save($flag,$data,$extend=[])
    {
        if(empty($flag))
        {
            // 添加
            $data['create_ts'] = time();
            return Db::table('simple_rbac_user')
                ->insertGetId($data);
        }
        else
        {
            // 编辑
            $data['update_ts'] = time();
            return Db::table('simple_rbac_user')
                ->where('id',$flag)
                ->update($data);
        }
    }
    
    /**
     * 获取详情
     * @param $where
     * @param array $extend
     * @return array|false|null|\PDOStatement|string|\think\Model
     */
    static public function get($where,$extend=[])
    {
        $handler = Db::table('simple_rbac_user');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->find();
    }
    
    /**
     * 删除
     * @param $flag
     * @param array $extend
     * @return int
     */
    static public function delete($flag,$extend=[])
    {
        return Db::table('simple_rbac_user')
            ->where('id',$flag)
            ->delete();
    }
}